<?php

/**
 * This is the model class for table "{{manufacturer}}".
 *
 * The followings are the available columns in table '{{manufacturer}}':
 * @property string $id
 * @property string $title
 * @property string $permalink
 * @property string $description
 * @property string $alt_title
 * @property string $alt_keywords
 * @property string $alt_description
 * @property integer $updated
 * @property integer $created
 */
class Manufacturer extends MainModel
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Manufacturer the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{manufacturer}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('permalink','ext.yiiext.components.translit.ETranslitFilter','translitAttribute'=>'title'),
			array('title', 'required'),
			array('updated, created', 'numerical', 'integerOnly'=>true),
			array('title, permalink, alt_title, alt_keywords', 'length', 'max'=>255),
			array('description, alt_description', 'safe'),
			array('created,updated','default','value'=>new CDbExpression(strtotime('now')),'setOnEmpty'=>false,'on'=>'insert'),
			array('updated','default','value'=>new CDbExpression(strtotime('now')),'setOnEmpty'=>false,'on'=>'update'),
			array('id, title, permalink, description, alt_title, alt_keywords, alt_description, updated, created', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations(){
		return array(
			'items' => array(self::HAS_MANY, 'Item', 'manufacturer'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'title' => 'Title',
			'permalink' => 'Permalink',
			'description' => 'Description',
			'alt_title' => 'Alt Title',
			'alt_keywords' => 'Alt Keywords',
			'alt_description' => 'Alt Description',
			'updated' => 'Updated',
			'created' => 'Created',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('permalink',$this->permalink,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('alt_title',$this->alt_title,true);
		$criteria->compare('alt_keywords',$this->alt_keywords,true);
		$criteria->compare('alt_description',$this->alt_description,true);
		$criteria->compare('updated',$this->updated);
		$criteria->compare('created',$this->created);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	public function items_count($category=''){
		echo count($this->items);
	}

}